//
//  NewsViewController.m
//  网易新闻
//
//  Created by angie on 15/11/10.
//  Copyright © 2015年 angie. All rights reserved.
//

#import "NewsViewController.h"
#import "NewsCollectionViewCell.h"
#import "NewsTableViewCell.h"
#import "NewsDetailViewController.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"

#define kBGColor     [UIColor colorWithRed:172.0/255.0 green:165.0/255.0 blue:162.0/255.0 alpha:1.0]

@interface NewsViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,retain)UITableView *newsTableView;
@property(nonatomic,retain)UICollectionView *newsCollectionView;
@property(nonatomic,retain)NSMutableArray *newsArray;
//滚动标头
@property(nonatomic,retain)UIScrollView *TitleScrollView;
//分类
@property(nonatomic,retain)NSMutableArray *classifiedArray;

@property (nonatomic, strong) NSMutableArray *frames;
@property (nonatomic, strong) UIColor *bgColor;

@end

@implementation NewsViewController

- (void)dealloc
{
    [_newsArray release];
    [_newsCollectionView release];
    [_newsTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"网易";
    /*
    self.imageName = @"btn_nav_collection.png";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:self.imageName] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];*/
    
    self.newsTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.newsTableView.delegate = self;
    self.newsTableView.dataSource = self;
    [self.newsTableView registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.newsTableView];
    [_newsTableView release];
    
    [self addScrollView];
  /*
    UICollectionViewFlowLayout *myFlowLayout = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    myFlowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 49 + 60 + 20, 20);
    myFlowLayout.minimumLineSpacing = 20;
    myFlowLayout.minimumInteritemSpacing = 20;
    myFlowLayout.itemSize = CGSizeMake((self.view.frame.size.width - 20) / 3.0 - 20, 180);
    
    self.newsCollectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:myFlowLayout];
        self.newsCollectionView.backgroundColor = [UIColor yellowColor];
    
    self.newsCollectionView.delegate = self;
    self.newsCollectionView.dataSource = self;
    
    [self.newsCollectionView registerClass:[NewsCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        [self.newsTableView addSubview:self.newsCollectionView];
    [_newsCollectionView release];*/
    
    self.newsArray = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php"];
    [AppTools getDataWithURL:url block:^(id result) {
        
        
        [self.newsTableView reloadData];
    }];
}

- (void)addScrollView {
    self.TitleScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 49, self.view.frame.size.width, 49)];
    self.TitleScrollView.backgroundColor = [UIColor redColor];
    self.TitleScrollView.delegate = self;
    [self.view addSubview:self.TitleScrollView];
    [_TitleScrollView release];

    self.TitleScrollView.contentSize = CGSizeMake(375*10, 0);
    self.TitleScrollView.contentOffset = CGPointMake(375, 0);
    self.TitleScrollView.pagingEnabled = YES;
    self.TitleScrollView.bounces = YES;
    
    //    for (int i = 0; i < self.classifiedArray; i++) {
    //        <#statements#>
    //    }
    
    for (int i = 0; i < 10; i++) {
        /*
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(i*375, 49, self.view.frame.size.width, 49)];
        scrollView.minimumZoomScale = 0.3;
        scrollView.maximumZoomScale = 10;
        scrollView.delegate = self;
        [self.TitleScrollView addSubview:scrollView];
        [scrollView release];
        */
        UIButton *button = 
        
        
        
        
        
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.newsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIndentifier = @"cell";
    NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    //9调用MovieTableViewCell的方法
//    [cell sendNewsList:[self.newsArray objectAtIndex:indexPath.row]];
    return cell;
}
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NewsDetailViewController *newsDetailVC = [[NewsDetailViewController alloc] init];
    [self.navigationController pushViewController:newsDetailVC animated:YES];
//    newsDetailVC.news = [self.newsArray objectAtIndex:indexPath.row];
    [newsDetailVC release];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
